package com.tanxin.bill.modules;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.View;

import com.blankj.utilcode.util.BarUtils;
import com.blankj.utilcode.util.TimeUtils;
import com.tanxin.bill.R;
import com.tanxin.bill.common.api.Contacts;
import com.tanxin.bill.common.base.BaseDrawActivity;
import com.tanxin.bill.common.base.BaseEvent;
import com.tanxin.bill.common.data.CustomerData;
import com.tanxin.bill.common.data.CustomerData_;
import com.tanxin.bill.modules.adapter.CustomerAdapter;

import java.util.List;

import butterknife.BindView;
import io.objectbox.Box;
import io.objectbox.android.AndroidScheduler;
import io.objectbox.query.Query;
import io.objectbox.reactive.DataObserver;

public class MainActivity extends BaseDrawActivity {

    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.fake_status_bar)
    View fakeStatusBar;
    @BindView(R.id.recycle)
    RecyclerView recycle;

    private CustomerAdapter customerAdapter;
    private Box<CustomerData> customerBox;
    private Query<CustomerData> customeQuery;

    @Override
    protected int bindLayout() {
        return R.layout.activity_main;
    }

    @Override
    protected void getBundleExtras(Bundle extras) {

    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        BarUtils.setStatusBarAlpha4Drawer(this, rootLayout, fakeStatusBar, Contacts.DEFAULT_ALPHA, true);
        toolbar.setTitle("待处理");

        customerBox = MyApp.getApplication().getBoxStore().boxFor(CustomerData.class);
        customeQuery = customerBox.query().equal(CustomerData_.type,1).less(CustomerData_.handleDate, TimeUtils.getNowDate()).build();
        customeQuery.subscribe(subscriptions).on(AndroidScheduler.mainThread())
                    .observer(new DataObserver<List<CustomerData>>() {
                        @Override
                        public void onData(@NonNull List<CustomerData> data) {
                            customerAdapter.setNewData(data);
                        }
                    });

        customerAdapter = new CustomerAdapter(null);
        recycle.setLayoutManager(new LinearLayoutManager(getContext()));
        recycle.setAdapter(customerAdapter);
    }

    @Override
    protected void onEventComing(BaseEvent event) {

    }


}
